import { createApp } from 'vue'
import { createPinia } from 'pinia';
import App from './App.vue'
import router from "./router";
import { useUserStore } from '@ui/vue/store';
import 'element-plus/dist/index.css'
import zUi from '@ui/components'
import '../../../common/css/index.scss'
const app = createApp(App)
const modules = import.meta.glob('./views/**/*.vue'), $coms: AsyncComponentObj<string> = {}
app.config.globalProperties.$loadCom = ({ pageUrl, params: { xtm }, pageId }: UserMenu) => {
  if (!$coms[pageId]) {
    const com = modules[`./views${pageUrl.replace(xtm, '')}/index.vue`]
    $coms[pageId] = defineAsyncComponent(() => {
      if (com) {
        return com().then((c: any) => c.default)
      } else {
        return import('@ui/views/404/index.vue')
      }
    })
  }
  return $coms[pageId]
}
app.use(createPinia())
app.use(zUi)
useUserStore().setPage(modules)
app.use(router as any)
app.mount(document.body) 